package src.view;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.*;

import src.controller.AddPostOfficeController;
import src.resource.PublicResource;



import com.jgoodies.forms.layout.*;
/*
 * Created by JFormDesigner on Tue May 25 20:13:21 ART 2010
 */



/**
 * @author Guillermo Exposito
 */
public class AddPostOffice extends JPanel {
	
	/**
	 * 
	 */
	private final String PATH=PublicResource.getPath();
	private static final long serialVersionUID = 1L;
	private AddPostOfficeController controller;
	private static AddPostOffice instance=null;
	
	public static AddPostOffice getInstance(AddPostOfficeController controller){
		if(instance==null)
			instance=new AddPostOffice(controller);
		return instance;
	}
	
	private AddPostOffice(AddPostOfficeController controller) {
		this.controller=controller;
		initComponents();
		this.btnSave.addActionListener(new ActionSavePostOffice());
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - Guillermo Exposito
		jPanelFields = new JPanel();
		lblTitle = new JLabel();
		lblName = new JLabel();
		txtName = new JTextField();
		label3 = new JLabel();
		label2 = new JLabel();
		btnSave = new JButton();
		CellConstraints cc = new CellConstraints();

		//======== this ========

	
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

		//======== jPanelFields ========
		{
			jPanelFields.setLayout(new FormLayout(
				"10dlu, $lcgap, 40dlu, $lcgap, 150dlu, 5dlu, 10dlu",
				"10dlu, $lgap, default, 5dlu, 3*($lgap, default), $lgap, 10dlu"));

			//---- lblTitle ----
			lblTitle.setText("Add Post Office");
			lblTitle.setHorizontalAlignment(SwingConstants.LEFT);
			lblTitle.setFont(new Font("Dialog", Font.PLAIN, 18));
			jPanelFields.add(lblTitle, cc.xywh(1, 3, 7, 1, CellConstraints.CENTER, CellConstraints.DEFAULT));

			//---- lblName ----
			lblName.setText("Name");
			lblName.setHorizontalAlignment(SwingConstants.RIGHT);
			jPanelFields.add(lblName, cc.xy(3, 6));
			jPanelFields.add(txtName, cc.xy(5, 6));

			//---- label3 ----
			label3.setText("*");
			label3.setForeground(Color.red);
			jPanelFields.add(label3, cc.xy(6, 6));

			//---- label2 ----
			label2.setText("* Required fields");
			label2.setForeground(Color.red);
			jPanelFields.add(label2, cc.xy(5, 8));

			//---- btnSave ----
			btnSave.setText("Save");
			jPanelFields.add(btnSave, cc.xywh(5, 10, 1, 1, CellConstraints.RIGHT, CellConstraints.DEFAULT));
		}
		add(jPanelFields);
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
		
		lblTitle.setIcon(new ImageIcon(PATH+"drawerAdd.png"));
		btnSave.setIcon(new ImageIcon(PATH+"document-save.png"));
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - Guillermo Exposito
	private JPanel jPanelFields;
	private JLabel lblTitle;
	private JLabel lblName;
	private JTextField txtName;
	private JLabel label3;
	private JLabel label2;
	private JButton btnSave;
	// JFormDesigner - End of variables declaration  //GEN-END:variables

	public JTextField getTxtName() {
		return txtName;
	}

	public void setTxtName(JTextField txtName) {
		this.txtName = txtName;
	}

	public JButton getBtnSave() {
		return btnSave;
	}

	public void setBtnSave(JButton btnSave) {
		this.btnSave = btnSave;
	}
	
	private class ActionSavePostOffice implements ActionListener {
		public void actionPerformed(ActionEvent e) {

			try {
				controller.performSavePostOffice();
				//DialogResource.showSaveSucessfully(btnSave.getLocation());
				
			} catch (RemoteException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}
	
	
	
	
}